<template>
	<div>
		<ButtonGroup>
	        <Button type="primary" @click="addData">添加数据</Button>
	        <Button type="error" @click="removes">批量删除</Button>
    	</ButtonGroup>
		<Input v-model="filter.name" class="textInp">
			<Button slot="append" icon="ios-search" @click="search" class="searchBtn"></Button>
		</Input>
		<Table border :columns="columns" :data="list"@on-selection-change="onSelectionChange"></Table>
		<Page :total="filter.total" :page-size="filter.limit" @on-change="onPageChange"   @on-page-size-change="onPageSizeChange"  show-sizer></Page>

		<Modal v-model="operateModal" title="数据处理"> 
		       	<Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="80">
		        <FormItem label="标题" prop="title">
		            <Input v-model="formValidate.title" placeholder="输入新闻标题"></Input>
		        </FormItem>
		        <FormItem label="内容" prop="content">
		            <Input v-model="formValidate.content" placeholder="输入新闻内容"></Input>
		        </FormItem>
		        <FormItem>
		            <Button type="primary" @click="handleSubmit('formValidate')">Submit</Button>
		            <Button type="ghost" @click="handleReset('formValidate')" style="margin-left: 8px">Reset</Button>
		        </FormItem>
		    </Form>
		    <div slot="footer">
		    	数据操作
		    </div>
	    </Modal>
	</div>
</template>

<style>
	.textInp{
		width: 500px;
		margin: 10px 0;
		border:1px solid #40E0D0;
		border-right-color: transparent; 
	}
	.textInp input{
		borcer-right:1px solid brown;
	}
	.textInp .searchBtn{
		background: #40E0D0;
		margin-right: -11px;
	}
	.textInp .searchBtn i{
		color: #8E8E38
	}
	
</style>

<script>
	import {Base} from '../../common/Base.js'

    export default {
    	mixins:[Base],
        data () {
            return {
            	moudel:'news',
            	formValidate: {
                    name: '',
                    password: '',
                },
                ruleValidate: {
                    name: [
                        { required: true, message: '用户名不能为空', trigger: 'blur' }
                    ],
                    password: [
                        { required: true, message: '密码不能为空', trigger: 'blur' },
                    ]
                },
                columns: [
                	{
                        type: 'selection',
                        width: 60,
                        align: 'center'
                    },
                    {
                        title: '新闻标题',
                        key: 'title',
                    },
                    {
                        title: '内容',
                        key: 'content',
                    },
                    {
                        title: '操作',
                        key: 'action',
                        width: 150,
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                                h('Button', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '5px'
                                    },
                                    on: {
                                        click: () => {
                                            this.editData(params);
                                        }
                                    }
                                }, '修改'),
                                h('Button', {
                                    props: {
                                        type: 'error',
                                        size: 'small'
                                    },
                                    on: {
                                        click: () => {
                                            this.remove(params)
                                        }
                                    }
                                }, '删除')
                            ]);
                        }
                    }
                ],
                list: [],
                filter:{
                	total:0,
	                limit:10,
	                page:1,
	                name:''
                },
                ids:[],
                id:0      
            }	
        },
    }
</script>